﻿using DotNetCore.CAP;
using EventBus.RabbitMQ;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Order.Common.IntegratedEvent
{
    public class IintegratedEventService : IntegratedEventService
    {
        private readonly IRabbitMqPublisher _rabbitMqPublisher;
        public IintegratedEventService(IRabbitMqPublisher rabbitMqPublisher)
        {
            _rabbitMqPublisher = rabbitMqPublisher;
        }

    
        /// <summary>
        /// RabbitMq异步发送命令
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        public async Task RabbitMqSendEventAsync(IntegratedEvent @event)
        {
            try
            {
                var queueName = @event.GetRoutingKey();
                await _rabbitMqPublisher.PublishAsync(queueName, @event);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
